package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单控制器
 *
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2024/2/25 09:13:01
 */
@RestController
@RequestMapping("/user/order")
@RequiredArgsConstructor
@Slf4j
public class OrderController {

    private final OrderService orderService;

    /**
     * 提交订单
     *
     * @param ordersSubmitDTO 订单提交dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/submit")
    public Result<?> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 付款
     *
     * @param ordersPaymentDTO 订单付款dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/payment")
    public Result<?> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        orderService.payment(ordersPaymentDTO);
        return Result.success();
    }

    /**
     * 薪酬成功
     *
     * @param number 数字
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/paySuccess/{number}")
    public Result<?> paySuccess(@PathVariable String number) {
        orderService.paySuccess(number);
        return Result.success();
    }


    /**
     * 历史订单
     *
     * @param ordersPageQueryDTO 订单查询页面dto
     * @return {@link Result}<{@link List}<{@link Orders}>>
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderService.historyOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 订单详情根据ID
     *
     * @param id id
     * @return {@link Result}<{@link OrderVO}>
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id) {
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }


    /**
     * 取消通过id
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/cancel/{id}")
    public Result<?> cancelById(@PathVariable Long id) {
        orderService.cancelById(id);
        return Result.success();
    }

    /**
     * 再来一单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/repetition/{id}")
    public Result<?> repetition(@PathVariable Long id) {
        orderService.repetition(id);
        return Result.success();
    }

    @GetMapping("/reminder/{orderId}")
    public Result<?> reminder(@PathVariable Long orderId) {
        orderService.reminder(orderId);
        return Result.success();
    }
}
